home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 August: Tool Chest / Dev.CD Aug 94.toast / New System Software Extensions / OpenDoc A6 / OpenDoc Parts Framework / OPF / Found / BCCollec / Support / BCNodes.h < prev    next >
Encoding:
Text File  |  1994-04-21  |  2.5 KB  |  105 lines  |  [TEXT/MPS ]

  1. //  The C++ Booch Components (Version 2.1)
  2. //  (C) Copyright 1990-1993 Grady Booch. All Rights Reserved.
  3. //
  4. //  BCNodes.h
  5. //
  6. //  This file contains the declaration of various node classes.
  7.  
  8. #ifndef BCNODES_H
  9. #define BCNODES_H 1
  10.  
  11. #include <stddef.h>
  12. #include "BCType.h"
  13.  
  14. // Class denoting an Item/Value pair
  15.  
  16. template<class Item, class Value>
  17. class BC_TPair {
  18. public:
  19.  
  20.   BC_TPair();
  21.   BC_TPair(const Item& item)
  22.     : fItem(item) {}
  23.   BC_TPair(const Item& item, const Value& value)
  24.     : fItem(item),
  25.       fValue(value) {}
  26.   BC_TPair(const BC_TPair<Item, Value>& a)
  27.     : fItem(a.fItem),
  28.       fValue(a.fValue) {}
  29.  
  30.   BC_TPair<Item, Value>& operator=(const BC_TPair<Item, Value>& a)
  31.     {fItem = a.fItem;
  32.      fValue = a.fValue;
  33.      return *this;}
  34.   BC_Boolean operator==(const BC_TPair<Item, Value>& a) const
  35.     {return (fItem == a.fItem);}
  36.   BC_Boolean operator!=(const BC_TPair<Item, Value>& a) const
  37.     {return !operator==(a);}
  38.  
  39.   Item fItem;
  40.   Value fValue;
  41.  
  42. };
  43.  
  44. // Class denoting a simple node consisting of an item and pointers to
  45. // the previous and next Items
  46.  
  47. template<class Item, class StorageManager>
  48. class BC_TNode {
  49. public:
  50.  
  51.   BC_TNode(const Item& i,
  52.            BC_TNode<Item, StorageManager>* previous,
  53.            BC_TNode<Item, StorageManager>* next)
  54.     : fItem(i),
  55.       fPrevious(previous),
  56.       fNext(next)
  57.     {if (previous)
  58.        previous->fNext = this;
  59.      if (next)
  60.        fNext->fPrevious = this;}
  61.  
  62.   Item fItem;
  63.   BC_TNode<Item, StorageManager>* fPrevious;
  64.   BC_TNode<Item, StorageManager>* fNext;
  65.  
  66.   static void* operator new(size_t);
  67.   static void operator delete(void*, size_t);
  68.  
  69. };
  70.  
  71. // Class denoting a simple node consisting of an item, a pointer to
  72. // the parent, pointers to the left and right items, and a reference count
  73.  
  74. template<class Item, class StorageManager>
  75. class BC_TBinaryNode {
  76. public:
  77.  
  78.   BC_TBinaryNode(const Item& i,
  79.                  BC_TBinaryNode<Item, StorageManager>* parent,
  80.                  BC_TBinaryNode<Item, StorageManager>* left,
  81.                  BC_TBinaryNode<Item, StorageManager>* right)
  82.     : fItem(i),
  83.       fParent(parent),
  84.       fLeft(left),
  85.       fRight(right),
  86.       fCount(1)
  87.     {if (left)
  88.        fLeft->fParent = this;
  89.      if (right)
  90.        fRight->fParent = this;}
  91.   ~BC_TBinaryNode();
  92.  
  93.   Item fItem;
  94.   BC_TBinaryNode<Item, StorageManager>* fParent;
  95.   BC_TBinaryNode<Item, StorageManager>* fLeft;
  96.   BC_TBinaryNode<Item, StorageManager>* fRight;
  97.   BC_Index fCount;
  98.  
  99.   static void* operator new(size_t);
  100.   static void operator delete(void*, size_t);
  101.  
  102. };
  103.  
  104. #endif
  105.